package com.jeesite.modules.ch.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ch.entity.ChLiushui;
import com.jeesite.modules.ch.service.ChLiushuiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 渠道流水Controller
 * @author 李寒冰
 * @version 2025-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/ch/chLiushui")
public class ChLiushuiController extends BaseController {

	@Autowired
	private ChLiushuiService chLiushuiService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ChLiushui get(String id, boolean isNewRecord) {
		return chLiushuiService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("ch:chLiushui:view")
	@RequestMapping(value = {"list", ""})
	public String list(ChLiushui chLiushui, Model model) {
		model.addAttribute("chLiushui", chLiushui);
		return "modules/ch/chLiushuiList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ch:chLiushui:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ChLiushui> listData(ChLiushui chLiushui, HttpServletRequest request, HttpServletResponse response) {
		chLiushui.setPage(new Page<>(request, response));
		Page<ChLiushui> page = chLiushuiService.findPage(chLiushui);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ch:chLiushui:view")
	@RequestMapping(value = "form")
	public String form(ChLiushui chLiushui, Model model) {
		model.addAttribute("chLiushui", chLiushui);
		return "modules/ch/chLiushuiForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ch:chLiushui:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ChLiushui chLiushui) {
		chLiushuiService.save(chLiushui);
		return renderResult(Global.TRUE, text("保存渠道流水成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("ch:chLiushui:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ChLiushui chLiushui) {
		chLiushuiService.delete(chLiushui);
		return renderResult(Global.TRUE, text("删除渠道流水成功！"));
	}
	
}